package com.dizang.ddd.business.impl;

import java.util.ArrayList;
import java.util.List;


import com.dizang.ddd.dto.ProjectNodeDTO;

public class CreateProjectByDefaultBusinessImpl extends AbstractCreateProjectBusiness{


	public boolean buildByObject(String path, String groupId, String projectName) {
		// p-common
		ProjectNodeDTO common = new ProjectNodeDTO();
		common.setGroupId(groupId);
		common.setName(projectName+"-common");
		common.setSubType("java");

		// p-domain
		ProjectNodeDTO domain = new ProjectNodeDTO();
		domain.setGroupId(groupId);
		domain.setName(projectName+"-domain");
		domain.setSubType("java");
		domain.addDependencies(projectName+"-common");

		// p-contract
		ProjectNodeDTO contract = new ProjectNodeDTO();
		contract.setGroupId(groupId);
		contract.setName(projectName+"-contract");
		contract.setSubType("java");

		// p-service
		ProjectNodeDTO service = new ProjectNodeDTO();
		service.setGroupId(groupId);
		service.setName(projectName+"-service");
		service.setSubType("java");
		service.addDependencies(projectName+"-domain");
		service.addDependencies(projectName+"-contract");

		// p-schedule
		ProjectNodeDTO schedule = new ProjectNodeDTO();
		schedule.setGroupId(groupId);
		schedule.setName(projectName+"-schedule");
		schedule.setSubType("java");
		schedule.addDependencies(projectName+"-domain");

		// parent
		ProjectNodeDTO projectNodeDTO = new ProjectNodeDTO();
		projectNodeDTO.setGroupId(groupId);
		projectNodeDTO.setName(projectName);
		projectNodeDTO.setType("project");
		projectNodeDTO.setSubType("java");
		List<ProjectNodeDTO> subNode = new ArrayList<>();

		subNode.add(common);
		subNode.add(domain);
		subNode.add(contract);
		subNode.add(service);
		subNode.add(schedule);
		projectNodeDTO.setSubNode(subNode);
		builEachProject(path, null, projectNodeDTO);
		return true;
	}
	
	@Override
	protected List<String> buildPackage(ProjectNodeDTO node) {
		return node.getPackages();
	}


}
